package com.eece496.Server;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eece496.Database.StudentGroups;
import com.eece496.Helpers.GroupInfo;

/**
 * Servlet implementation class TAViewGroupsServlet
 */
public class TAViewGroupsServlet extends MasterServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TAViewGroupsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Connect();
		try {
			String firstname = request.getParameter("firstname");
			String lastname = request.getParameter("lastname");
			String courseNumber = request.getParameter("courseNumber");
			String sectionNumber = request.getParameter("sectionNumber");
			String tID = request.getParameter("TAID");

			StudentGroups StudentGroupsDB = new StudentGroups();
			StudentGroupsDB.Setup(connection);
			
			//Get all student groups
			ArrayList<GroupInfo> Info = new ArrayList<GroupInfo>();

			Info = StudentGroupsDB.GetAllGroups(courseNumber, sectionNumber);

			request.setAttribute("firstname", firstname);
			request.setAttribute("lastname", lastname);
			request.setAttribute("courseNumber", courseNumber);
			request.setAttribute("sectionNumber", sectionNumber);
			request.setAttribute("GroupsInfo", Info);
			request.setAttribute("TAID", tID);
			request.getRequestDispatcher(
					"/TA/TA-View-Groups.jsp").forward(
					request, response);

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
